package com.pt25.gateway;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.ServerResponse;

import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
import static org.springframework.web.reactive.function.server.ServerResponse.ok;


/**
 * 解决：
 * org.springframework.web.reactive.resource.NoResourceFoundException: 404 NOT_FOUND "No static resource favicon.ico."
 */

@Configuration
public class FaviconConfig {
    /**
     * 提供默认的 favicon.ico
     */
    @Bean
    public RouterFunction<ServerResponse> faviconRouter() {
        return route(GET("/favicon.ico"),
                request -> ok()
                        .contentType(MediaType.parseMediaType("image/x-icon"))
                        .bodyValue(new byte[0])); // 返回空的 favicon
    }
}
